package com.thot.timyag.core.support;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;

/**
 * @author yangjf
 * @version 0.1.0
 * @time 2019/4/22
 */
public class SelfClassPathScanner extends ClassPathBeanDefinitionScanner {
    private ClassLoader classLoader;

    public SelfClassPathScanner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    public void setClassLoader(ClassLoader cl) {
        this.classLoader = cl;
    }

    @Override
    protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) {
        super.postProcessBeanDefinition(beanDefinition, beanName);
        try {
            beanDefinition.setBeanClass(classLoader.loadClass(beanDefinition.getBeanClassName()));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }


}
